package MINISTOP.AD.DATA;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;

import WIZ.FR.COM.DOBJ;
import WIZ.FR.DAO.Connector;
import WIZ.FR.UTIL.WizUtil;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import WIZ.FR.COM.*;
import WIZ.FR.DAO.*;
import WIZ.FR.MSG.*;
import WIZ.FR.UTIL.*;

public class TEST_src {


    public static void main(String[] args){

    	TEST_src sdt = new TEST_src();
    	
    	

    	System.out.println(sdt.getWeekYear());

    } 

    public String getWeekYear(){
    	SimpleDateFormat formatter2 = new SimpleDateFormat("yyyyMMdd");
    	String pattern = "yyyyw";
    	
    	String ymd = "20130201";
    	String result= "";
    	    	
    	try {
    		Date date = formatter2.parse(ymd);
			SimpleDateFormat formatter = new SimpleDateFormat(pattern,new Locale("ko","KOREA"));
			
			Calendar cal = new GregorianCalendar();			
			cal.setTime(date);			
			cal.add(cal.DATE, -7);
			date = cal.getTime();
			
	    	System.out.println("date = " + date);
	    	

	    	
	    	
	    	result = formatter.format(date);
	    	
	    	
	    	System.out.println("result : " + result);
	    	

	    	
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally
		{
	    	if(result.length() < 6)
	    	{
	    		result = result.substring(0,4)+"0"+result.substring(4);
	    	}
		}
    	
    	
//    	formatter = new SimpleDateFormat(pattern,new Locale("ko","KOREA"));
//    	cal = new GregorianCalendar();
//    	//cal.add(cal.DATE, -7);
//    	//date = cal.getTime();
//    	System.out.println("date = " + date);
//    	result = formatter.format(date);
    	

    	
		return result;
    	
    }

}
